package com.neu.envprotection.airQuality.controller;

import com.neu.envprotection.airQuality.dto.req.AirQualityReqDto;
import com.neu.envprotection.airQuality.dto.req.UserSelectReqDto;
import com.neu.envprotection.airQuality.dto.resp.AirQHistoryRespDto;
import com.neu.envprotection.airQuality.dto.resp.AirQualityRespDto;
import com.neu.envprotection.airQuality.service.InvestigatorService;
import com.neu.envprotection.common.constant.SystemConfigConsts;
import com.neu.envprotection.common.resp.RestResp;



import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 网格员（调查员）模块
 */

@RestController
@RequestMapping("/api/investigator")
@RequiredArgsConstructor
@SecurityRequirement(name = SystemConfigConsts.HTTP_AUTH_HEADER_NAME)
@Tag(name = "网格员端接口")
@Slf4j
public class InvestigatorController {
    @Autowired
    private InvestigatorService investigatorService;

    @PostMapping("/airqualitylist")
    @Operation(summary = "空气质量列表")
    private RestResp<List<AirQualityRespDto>> getAirQuality(@RequestBody UserSelectReqDto userSelectReqDto){
        return investigatorService.getAirQuality(userSelectReqDto);
    }

    @PostMapping("/airqualityinfo")
    @Operation(summary = "空气质量查看与提交")
    private RestResp<Void> submitAirQuality(@RequestBody AirQualityReqDto airQualityReqDto){
        //System.out.println(airQualityReqDto);
        airQualityReqDto.setUpDateTime(LocalDateTime.now());
        if(investigatorService.submitAirQuality(airQualityReqDto).getData()==1){
            return RestResp.ok();
        }else {
            return RestResp.error();
        }
    }

    @PostMapping("/airqualityhistory")
    @Operation(summary = "实测历史")
    private RestResp<List<AirQHistoryRespDto>> getAirQHistory(@RequestBody UserSelectReqDto userSelectReqDto){
        return investigatorService.getAirQHistoryById(userSelectReqDto);
    }
}
